/* 	MediaStream
*	Display group
*	
*	IMPORTANT
*
*	
*										*/
var SocialStream = function( vars )	{

	Object.extend( obj = $$( '.SocialStream' ).pop(), SocialStream.proto );
	if( vars )	obj.vars = vars;
	
	return obj;
}


SocialStream.proto = {
	
	current		: 0,
	
	load		: function( el ) {
		
		this.current += ( el.currentTarget.hasClassName( "left" ) )? -1 : 1;
		this.select( ".month" )[0].update( "..." );
		
		xhttp.send( '/xhttp.mod', { mod: "calendar.field", action: "mini", vars: { current: this.current }}, this.pull_response.bind( this ));
	},
	
	seed		: function( set ) {
		
		
	},
	
	fillnode	: function( span, n) {
			
			
	},
	
	dominate	: function ( ref ) {
	
		this.select( "li.image" ).each( function ( el ) {
			el.observe( "click", this.change.bind( this, ref, el ) );
		}, this );
	
	},
	
	change			: function( ref, el ) {
		
		var id	= el.down().identify();
		xhttp.send( '/xhttp.mod', { mod: "social.stream", action: "fill", vars: { id: id, vars: this.vars }}, this.pull_response.bind( this, ref ));
			
	},
	
	pull_response	: function( ref, response ) {
	
		set = response.responseText;
		$( ref ).update( set );
	
	},
	
	expand		: function( cond ) {
		
		if( cond == "first" ) this.children[0].children[0].addClassName( "active" );
		else if( !cond ) this.children.invoke( "addClassName", "active");
		else for( n=0; n<cond; n++ ) chlidren[ n ].addClassName( "active" );
	},

	
	slideshow	: function() {
	
		this.select( 'a.navigate' ).each( function( el ) {
			
			el.observe( 'click', this.fader.bind( this, el ));
		}, this );
	},
	
	fader		: function( el ) {
	
		this.select( 'a.navigate' ).each( function( el ) {
			el.removeClassName( 'active' );
		});
		el.addClassName( 'active' );

		this.select( 'li.movie.active' ).each( function( el ) {
			el.removeClassName( 'active' );
			el.addClassName( 'hide' );
		});
		
		$( 'ref' + el.rel ).addClassName( 'active' );
	
	},


	prepstream		: function() {
		
		this.select( ".playIt" ).each( function( el ) {
					
			el.observe( "click", this.flipstream );
		}, this );
		
	},
	
	flipstream		: function() {

		this.up(0).next().removeClassName("hide");
		this.up(0).addClassName("hide");
		
	},
	
	splitter		: function(){
		
		this.vars.showed= 0;
		
		var streams		= this.select( 'li.movie' );
		var next		= this.select( '.nav.next' ).pop();
		var prev 		= this.select( '.nav.prev' ).pop();
		
		prev.hide();
		
		next.observe( 'click', this.shower.bind( this, this.vars.showed, 'next' ));
		prev.observe( 'click', this.shower.bind( this, this.vars.showed, 'prev' ));
				
		streams.each( function( el, i ) {
			if( i < this.vars.splitter )
				el.show();
			else
				el.hide(); 
		}.bind( this ));
	},
	
	shower		: function( nr, what ) {
	
		if( what == 'next' )
			this.vars.showed = this.vars.showed + Number( nr + this.vars.splitter );
			
		if( what == 'prev' )
			this.vars.showed = this.vars.showed + ( Number( nr ) - Number( this.vars.splitter ));

		var streams		= this.select( 'li.movie' );
		var tot_streams	= streams.length;
		var next		= this.select( '.nav.next' ).pop();
		var prev 		= this.select( '.nav.prev' ).pop();
		
		if( this.vars.showed == 0 )
			prev.hide()
		else
			prev.show();
			
		if( this.vars.showed > ( Number( tot_streams ) - Number( this.vars.splitter )))
			next.hide();
		else
			next.show();
			
		streams.each( function( el, i ) {
			el.hide();			
			if( i >= this.vars.showed && i < Number( this.vars.showed ) + Number( this.vars.splitter ))
				el.show();
		}.bind( this ));
				
	},
		
	bubble		: function() {}

}

SocialStream.proto_info = {
	
	init		: function() {
	
	},
	
	hover		: function() {

	},
	
	bubble		: function() {
		
	}
}